#!/usr/bin/python
#
# Chinwei Hu, Apr 2010
#
# cvs_mlist.py takes cnx.cvs and turn into a list of module IDs
#
# ./cvs_mlist.py [csv filename] [savename]
# 

import os
import csv
import sys

def main():
  args = sys.argv[1:]
  csvfile = args[0]
  savefile = args[1]
  mlist = csv2dict(csvfile,'Id') 
  print mlist
  outfile = open(savefile,'w')
  outfile.write('\n'.join(mlist))
  outfile.close()
  
def csv2dict(filename,attribute):
  reader = csv.reader(open(filename,'rb'))
  list = []
  for row in reader:
    list.append(row)
  out = list[0].index(attribute)
  outlist = [row[out] for row in list[1:]]
  return outlist
  
if __name__ == '__main__':
  main()